package models

import (
	"github.com/beego/beego/v2/client/orm"
)

type ErpEntryreturnData struct {
	Id           int64
	Entry        *ErpEntryreturn    `orm:"rel(fk);null;on_delete(do_nothing)"`
	Products     *ErpProducts       `orm:"rel(fk);null;on_delete(do_nothing)"`
	Acceptance   *ErpAcceptanceData `orm:"rel(fk);null;on_delete(do_nothing)"` //验收ID
	Snd          *ErpProductsSnd    `orm:"rel(fk);null;on_delete(do_nothing)"`
	InventoryId  int64 //库存ID
	Amount       int64 `json:"purchase_num"`
	UnitPrice    float64
	Diopter      string `json:"-" orm:"-"` //屈光度
	Astigmatism  string `json:"-" orm:"-"` //散光度
	Addlight     string `json:"-" orm:"-"` //下加光
	ColourNumber string `json:"-" orm:"-"`
	ModelNumber  string `json:"-" orm:"-"`
	Size         string `json:"-" orm:"-"` //尺寸
	FunctionInfo string `json:"-" orm:"-"` //功效
	FilmColor    string `json:"-" orm:"-"` //膜层颜色
	Genre        string `json:"-" orm:"-"` //框型
	MiddleId     int64                     //中间表ID
	Remarks      string
}

func (a *ErpEntryreturnData) TableName() string {
	return ErpEntryreturnDataTableName()
}

func ErpEntryreturnDataTableName() string {
	return TableName("erp_entryreturn_data")
}

func ErpEntryreturnDataList(entryId int64) []*ErpEntryreturnData {
	list := make([]*ErpEntryreturnData, 0)
	o := orm.NewOrm().QueryTable(ErpEntryreturnDataTableName()).RelatedSel("Products", "Acceptance", "Snd")
	o.Filter("Entry__id", entryId).All(&list)
	return list
}

func ErpEntryreturnDataAdd(c *ErpEntryreturnData) (int64, error) {

	return orm.NewOrm().Insert(c)
}
